#include<bits/stdc++.h>
using namespace std;

int t;
int n;
int a[200005];

long long dfs(int p, int c, int lst, long long sum)
{
    long long maxn;
    if(p == n)
    {
        maxn = max((a[p] == a[lst])? a[p] : 0,
                    (a[p] == a[p - 1])? a[p] : 0);
    }
    else
    {
        maxn = max(dfs(p + 1, 1, p, ((a[p] == a[lst])? a[p] : 0)),
                   dfs(p + 1, 0, lst, ((a[p] == a[p - 1])? a[p] : 0)));
        maxn = max(maxn, max(dfs(p + 1, 0, p, ((a[p] == a[lst])? a[p] : 0)),
                   dfs(p + 1, 1, lst, ((a[p] == a[p - 1])? a[p] : 0))));
    }
    return sum + maxn;
}

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        printf("%lld\n", max(dfs(1, 0, 0, 0), dfs(1, 1, 0, 0)));
    }
    return 0;
}
